package com.cloudsigns.factorymanager2.project.presenter;

import android.os.Handler;

import com.cloudsigns.factorymanager2.produce.bean.Produce_ProductBean;
import com.cloudsigns.factorymanager2.project.iview.IProductDetailView;
import com.cloudsigns.factorymanager2.project.model.IProductDetailModel;
import com.cloudsigns.factorymanager2.project.model.ProductDetailModel;

public class ProductDetailPresenter {
    private IProductDetailView view;
    private IProductDetailModel model;
    private Handler mHandler = new Handler();

    public ProductDetailPresenter(IProductDetailView iView) {
        this.view = iView;
        model = new ProductDetailModel();
    }

    public void getProductDetail() {
        model.getProductDetail(view.getOrderId(), view.getProductId(), new ProductDetailModel.OnProductDetailListener() {
            @Override
            public void successed(final Produce_ProductBean productBean) {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getProductDetailSuccessed(productBean);
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void failed(final String desc) {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getProductDetailFailed(desc);
                        view.hideLoading();
                    }
                });
            }
        });
    }
}
